package main

import (
	"fmt"
	"time"

	"gitee.com/chen_wei_jing/kinx/zconf"

	"gitee.com/chen_wei_jing/kinx/ziface"
	"gitee.com/chen_wei_jing/kinx/znet"
)

type RegisterRouter struct {
	znet.BaseRouter
}

func (r *RegisterRouter) Handle(req ziface.IRequest) {
	fmt.Println("[消息]:", string(req.GetMessage().GetData()))
	req.GetConnection().SendMsg(1, []byte("我是服务器,恭喜你注册成功！"))
}

func main() {
	s := znet.NewUserConfServer(&zconf.Config{
		Mode:               "kcp",
		KcpPort:            7777,
		KcpRecvWindow:      128,
		KcpSendWindow:      128,
		KcpStreamMode:      true,
		KcpACKNoDelay:      false,
		KcpFecDataShards:   10, //代表每10个原始数据块 发3个校验数据块
		KcpFecParityShards: 3,
		HeartbeatMax:       10, // 10秒内没有收到数据包,表示断线
	})

	s.AddRouter(1, &RegisterRouter{})

	s.SetOnConnStart(func(conn ziface.IConnection) {
		fmt.Println("--> OnConnStart")
	})

	s.StartHeartBeat(8 * time.Second)
	s.Serve()
}
